//
//  PKContentServcies.swift
//  Panku
//
//  Created by mac on 2017/4/12.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit

import ReactiveCocoa
import ReactiveSwift
import Result

class PKContentServcies: NSObject {
    //获取评论列表
    //entityType: 0:直播,1:推文,2:短视频'
    class func getContentList(entityId:Int,entityType:Int,offset:Int,max:Int,del:Int,queryTime:String) -> SignalProducer<Any,NSError> {
        
        let url = PKUrl.CONTENTS_URL
        let parameters:[String : Any] = ["entityId":entityId,
                                         "entityType":entityType,
                                         "offset":offset,
                                         "max":max,
                                         "del":del,
                                         "queryTime":queryTime];
        
        let networkUtilsFactor = PKNetworkUtilsHelper.factory()
        let networkUtils = networkUtilsFactor()
        return networkUtils.request(url: url, method: .put, parameters: parameters, headers: nil).map({ (json) -> [PKContentModel] in
            
            return PKContentModel.mj_objectArray(withKeyValuesArray: json) as NSArray as! [PKContentModel]
        })
        
    }
    
    //评论点赞
    class func voteContent(id:Int) -> SignalProducer<Any,NSError> {
        
        let url = PKUrl.CONTENTS_URL + "/" + "\(id)" + "/vote"
        
        let networkUtilsFactor = PKNetworkUtilsHelper.factory()
        let networkUtils = networkUtilsFactor()
        return networkUtils.request(url: url, method: .put, parameters: nil, headers: nil)
    }
    
    //评论分享
    class func shareContent(id:Int) -> SignalProducer<Any,NSError> {
        
        let url = PKUrl.CONTENTS_URL + "/" + "\(id)" + "/share"
        
        let networkUtilsFactor = PKNetworkUtilsHelper.factory()
        let networkUtils = networkUtilsFactor()
        return networkUtils.request(url: url, method: .put, parameters: nil, headers: nil)
    }
    
    //新建评论
    class func newContent(entityId:Int,entityType:Int,reply:Int,createId:Int,createName:String,replyId:Int,replyName:String,content:String) -> SignalProducer<Any,NSError>{
        
        let url = PKUrl.CONTENTS_URL
        let parameters : [String:Any] = ["entityId":entityId,
                                         "entityType":entityType,
                                         "reply":reply,
                                         "createId":createId,
                                         "createName":createName,
                                         "replyId":replyId,
                                         "replyName":replyName,
                                         "content":content];
        
        let networkUtilsFactor = PKNetworkUtilsHelper.factory()
        let networkUtils = networkUtilsFactor()
        return networkUtils.request(url: url, method: .post, parameters: parameters, headers: nil)
    }
}
